var app = getApp();
var _id = '';
var isclose = true;
var getList = function () {
  var _this = this;
  //调用应用实例的方法获取全局数据
  app.getUserInfo(function (userInfo) {
    wx.request({
      url: app.globalData.domain + 'api/wxapp_activity_user?id=' + _id + '&openId=' + userInfo.openId,
      success: function (res) {
        if (res && res.data.pjuser && res.data.pjuser.length) {
          _this.setData(JSON.parse(res.data.pjuser[0].app_project.templ));
        }
        _this.setData({
          pjuser: res.data.pjuser,
        });
        wx.hideNavigationBarLoading();
      }
    });
  });
};

Page({
  data: {

  },
  onLoad: function (options) {
    _id = options.id;
    this.setData({
      id: _id
    })
    wx.setNavigationBarTitle({
      title: '项目详情'
    });
    getList.call(this);
  },
  onShow: function () {
    wx.showNavigationBarLoading();
  },

  delete: function (e) {
    var id = e.target.dataset.id;
    console.info(e);
    if (!id) {
      return;
    }
    console.info(id);
    var _this = this;
    wx.showModal({
      title: '删除数据',
      content: '删除后数据无法恢复，是否删除？',
      success: function (res) {
        if (res.confirm) {
          app.getUserInfo(function (userInfo) {
            wx.request({
              url: app.globalData.domain + 'api/wxapp_delete?pjuserid=' + id + '&openId=' + userInfo.openId + '&pjid=' + _id,
              success: function (res) {
                wx.showToast({
                  title: '删除成功',
                  icon: 'success',
                  duration: 2000
                })
                _this.setData({
                  pjuser: null,
                });
              }
            });
          })

        }

      }
    })

  },
  bindxq: function () {
    wx.navigateTo({
      url: '/pages/detail/detail?id=' + _id
    });
  },

  onHide: function () {
    isclose = false;
  },
  onUnload: function () {
    isclose = true;
  },
  onShow: function () {
    wx.showNavigationBarLoading();
    if (!isclose) {
      getList.call(this);
    }
  },




})